package P7.T05;

public class Account {
    private int balance = 0;
    public synchronized void put(){
        System.out.println(Thread.currentThread().getName()+" "+balance);
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        balance+=100;
        System.out.println(Thread.currentThread().getName()+" save 100");
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println(Thread.currentThread().getName()+" "+balance);
    }
    public synchronized void get(){
        System.out.println(Thread.currentThread().getName()+" "+balance);
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        balance-=100;
        System.out.println(Thread.currentThread().getName()+" fetch 100");
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println(Thread.currentThread().getName()+" "+balance);
    }
}
